﻿using System;
using System.ComponentModel;

namespace MathematicallySafe.HeadCounter.ViewModels
{
    public abstract class ViewModelBase : INotifyPropertyChanged, IDisposable
    {
        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        protected void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;

            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        protected virtual void SubscribeEvents() { }

        protected virtual void UnsubscribeEvents() { }

        public void Initialise()
        {
            SubscribeEvents();
        }

        public void Dispose()
        {
            UnsubscribeEvents();
        }
    }
}